package commandPatern;

import gui.abstracts.AbstractTable;
import gui.containerDate.Item;

import java.sql.SQLException;

import bean.GroupBean;
import bean.UniversityBean;

import patern.Sybject;

import dao.UniversityDAO;

public class Delete implements Command {
	
	private UniversityBean university;
	private int nrRow;
	private AbstractTable abstractTable;
	
	public Delete(UniversityBean universityOld, int nrRow, AbstractTable abstractTable) {
		this.university = universityOld;
		this.nrRow = nrRow;
		this.abstractTable = abstractTable;
	}
	
	public void undo() throws InstantiationException, IllegalAccessException,
			ClassNotFoundException, SQLException {
		
		UniversityDAO uDao = university.getDAO();
		uDao.Insert(university);
		abstractTable.getDefaultTableMOdel().insertRow(nrRow, university.getRow());
		
		Sybject.getInstance().addNotifyObs(new Item(((GroupBean) university).getId(),
				((GroupBean) university).getDenumire()));
	}

	@Override
	public void rendoo() throws InstantiationException, IllegalAccessException,
			ClassNotFoundException, SQLException {
		UniversityDAO uDao = university.getDAO();
		uDao.Delet(university);
		
		abstractTable.getDefaultTableMOdel().removeRow(nrRow);
		Sybject.getInstance().removeNotifyOps(new Item(((GroupBean) university).getId(),
				((GroupBean) university).getDenumire()));
	}

}
